package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/12/12
 */
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @Cacheable(key = "'selectIndexCourseAndTeacher'",value = "courseAndteacher")
    //查询钱八条热门课程、前四条名师
    @GetMapping("/index")
    public R index() {
        List<EduCourse> courseList = courseService.list(new QueryWrapper<EduCourse>().lambda().orderByDesc(EduCourse::getId).last("limit 8"));
        List<EduTeacher> teacherList = teacherService.list(new QueryWrapper<EduTeacher>().lambda().orderByDesc(EduTeacher::getId).last("limit 4"));
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);

    }
}
